<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-10-19
 * Time: 14:39
 */

namespace app\src\sendsms\action;


use app\src\base\logic\BaseLogic;
use app\src\role\model\RoleTask;
use app\src\base\action\BaseAction;

class SendsmsAction extends BaseAction
{
    //调用，创建并发送手机验证码
    public function send_sms($mobile,$sms){
        //生成验证码

        if(empty($mobile)) $this->error('手机号为空');

        $send=$this->send_message($mobile,$sms);
        if(empty($send)) $this->success('短信已发送','');

        $this->error('发送失败','');
    }
    //发送手机验证码
    public function send_message($moblie,$sms){
        //发送短信操作
        $account='d82e8q';
        $pswd='6MgEG71w';
        $mse=$sms;
        $url = "http://send.18sms.com/msg/HttpBatchSendSM?account=".$account."&pswd=".$pswd."&mobile=".$moblie."&msg=".$mse."&needstatus=".true;
        //http://send.18sms.com/msg/HttpBatchSendSM?account=test01&pswd=123456&mobile=18900000000&msg=您的验证码：1234&needstatus=true&extno=1234
        $arr = json_decode($this->curlGet($url), true);

        return $arr;

    }
    protected function curlGet($url) {
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $temp = curl_exec($ch);

        return $temp;
    }


}
